<template>
  <el-dialog
      title="导出数据"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
      <el-form-item label="文件名" prop="fileName">
        <el-input v-model="dataForm.fileName" placeholder="请输入文件名"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        fileName: ''
      },
      dataRule: {
        fileName: [
          {
            required: true,
            message: '文件名不能为空',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$confirm('确认导出数据吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: "warning"
          }).then(() => {
            this.visible = false
            this.$emit('export', this.dataForm.fileName)
          }).catch(() => {
            this.$message.info("已取消导出");
          })
        }
      })
    }
  }
}
</script>
